
def count_and_list_level_one_headers(file_path):
    # 初始化一级标题计数器和标题列表
    level_one_header_count = 0
    level_one_headers = []

    # 打开并读取文件
    with open(file_path, 'r', encoding='utf-8') as file:
        for line in file:
            # 去除行首尾的空白字符
            stripped_line = line.strip()
            # 检查是否为一级标题
            if stripped_line.startswith('# ') and not stripped_line.startswith('##'):
                level_one_header_count += 1
                level_one_headers.append(stripped_line)

    return level_one_header_count, level_one_headers

# 获取合规性政策文件中一级标题的个数和列表
# file_path = "/root/SHAI_MXZ5/CrossBorderAIChallenge/input/md/us-amazon-prohibited-policy.md"
# 获取合规性政策文件中一级标题的个数和列表
file_path = "/root/SHAI_MXZ5/CrossBorderAIChallenge/input/md/us-amazon-compliance-policy.md"
# 调用函数并打印结果
count, headers = count_and_list_level_one_headers(file_path)
print(f"一级标题的个数: {count}")
print("一级标题列表:")
for header in headers:
    print(header)